package com.md.untils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisUntil {
    public static SqlSession OpenSession() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
//        sql session 会话（连接） Factory工厂
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(inputStream);
//        通过工厂打开会话Sqlsession
        SqlSession sqlSession = ssf.openSession();
        return sqlSession;
    }
}
